package com.sky.web.app;

import com.sky.dto.SetmealPageDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
public class AppSetmealController {

    @Autowired
    private SetmealService setmealService;


    //根据分类id查询起售的套餐列表
    @Cacheable(value = "setmealCache",key = "#categoryId")
    //别导错包->@Cacheable：先查询缓存，没有再查数据库同步到缓存-->相当于if~else
    @GetMapping("/list")
    public Result findList(@RequestParam Long categoryId) {//1. 接收参数
        //2. 封装dto
        SetmealPageDTO setmealPageDTO = SetmealPageDTO.builder()
                .categoryId(categoryId)
                .status(1).build();//启售
        //3. 调用service查询
        List<SetmealVO> list = setmealService.findList(setmealPageDTO);
        //4. 返回结果
        return Result.success(list);
    }

    //根据id查询套餐的菜品列表
    @GetMapping("/dish/{id}")
    public Result findDishList(@PathVariable("id") Long id) {
        List<DishItemVO> list = setmealService.findDishList(id);
        //4. 返回结果
        return Result.success(list);
    }
}